package com.woorigil.social.parser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.woorigil.social.Context;
import com.woorigil.social.domain.deal.Deal;

abstract public class CategoryMapper {
	public static final int DEPTH_ONE_CATEGORY_SHOPPING = 1;
	public static final int DEPTH_ONE_CATEGORY_FOOD = 13;
	public static final int DEPTH_ONE_CATEGORY_CULTURE = 27;
	public static final int DEPTH_ONE_CATEGORY_TRAVEL = 34;
	public static final int DEPTH_ONE_CATEGORY_BUTI = 40;
	
	public static boolean isLocalMenu(int mainCategoryId) {
		if (DEPTH_ONE_CATEGORY_FOOD == mainCategoryId) {
			return true;
		}
		if (DEPTH_ONE_CATEGORY_BUTI == mainCategoryId) {
			return true;
		}
		return false;
	}
	
	public static class CategoryName {
		private String mainName;
		private String subName;
		
		public CategoryName(String mainName, String subName) {
			this.mainName = mainName;
			this.subName = subName;
		}
		public String getMainName() {
			return mainName;
		}
		public String getSubName() {
			return subName;
		}
	}
	
	public List<CategoryKeyword> categoryKeywords = new ArrayList<CategoryKeyword>() {{
		add(new CategoryKeyword("맛집", "", "양식,맛집,샤브,고기,곱창,오리,테이크,조개,무한리필,돈까스,도시락,참치"));
		add(new CategoryKeyword("뷰티/생활", "", "미용실,맛사지,헤어,끌레지오,태국,속눈썹"));
		add(new CategoryKeyword("쇼핑", "가전", "가전"));
		add(new CategoryKeyword("쇼핑", "생활/주방", "생활,주방,욕실"));
		add(new CategoryKeyword("쇼핑", "출산/유아동", "출산,유아"));
		add(new CategoryKeyword("쇼핑", "뷰티", "뷰티,다이어트,메이크업,이미용,바디,헤어,스킨케어"));
		add(new CategoryKeyword("쇼핑", "식품", "식품,커피,음료,과일"));
		add(new CategoryKeyword("쇼핑", "스포츠/레저", "스포츠"));
		add(new CategoryKeyword("쇼핑", "디지털", "컴퓨터,주변기기,디지털,자동차"));
		add(new CategoryKeyword("쇼핑", "패션잡화", "가방,지갑,슈즈,액세서리,소품,신발,시계,반지,쥬얼리"));
		add(new CategoryKeyword("쇼핑", "홈/데코/취미", "홈,데코,인테리어"));
		add(new CategoryKeyword("쇼핑", "의류", "의류,속옷"));
		add(new CategoryKeyword("여행/레저", "레저/스포츠", "레저,취미,기타"));
		add(new CategoryKeyword("여행/레저", "숙박", "호텔,리조트,펜션"));
		add(new CategoryKeyword("여행/레저", "국내", "국내여행"));
		add(new CategoryKeyword("여행/레저", "해외", "해외여행,항공권,해외여행"));		
		add(new CategoryKeyword("문화", "뮤지컬/연극", "공연,전시"));		
	}};
	
	public List<String> locals = new ArrayList<String>() {{
		add("전국");
		add("서울");
		add("경기");
		add("인천");
		add("부천");
		add("대전");
		add("충청");
		add("대구");
		add("부산");
		add("경상");
		add("전라");
		add("광주");
		add("강원");
		add("제주");
	}};
	
	public Map<String, List<String>> travels = new HashMap<String, List<String>>() {{
		put("레저/스포츠", Arrays.asList("레저/취미/기타"));
		put("숙박", Arrays.asList("호텔/리조트/펜션"));
		put("국내", Arrays.asList("국내여행"));
		put("해외", Arrays.asList("해외여행/항공권", "해외여행"));
	}};
	public Map<String, List<String>> cultures = new HashMap<String, List<String>>() {{
		put("뮤지컬/연극", Arrays.asList("공연/전시"));
	}};	
	
	//키즈카페
	public Map<Integer, List<String>> food = new HashMap<Integer, List<String>>() {{
		put(13, Arrays.asList("식도락")); //"맛집"
	}};	
	
	public Map<Integer, List<String>> buti = new HashMap<Integer, List<String>>() {{
		put(40, Arrays.asList("뷰티", "교육", "기타")); //뷰티/생활
	}};
	
	abstract public int getCategoryId(Deal deal);
	
	protected int getCategoryIdFromLocal(Deal deal) {
		for (Entry<Integer, List<String>> entry : food.entrySet()) {
			for (String each : entry.getValue()) {
				if (each.equals(deal.getSection4())) {
					return entry.getKey();
				}
			}
		}
		for (Entry<Integer, List<String>> entry : buti.entrySet()) {
			for (String each : entry.getValue()) {
				if (each.equals(deal.getSection4())) {
					return entry.getKey();
				}
			}
		}
		
//		제주여행
		if (deal.getSection2().contains("여행")) {
			return CategoryMapper.DEPTH_ONE_CATEGORY_TRAVEL;
		}
		return 100;
	}
	
	protected int getCategoryId(Deal deal, CategoryName categoryName) {
		for (CategoryKeyword categoryKeyword : categoryKeywords) {
			if (categoryKeyword.getMainName().equals(categoryName.getMainName())) {
				if (categoryKeyword.getKeywords().contains(categoryName.getSubName())) {
					return Context.getMainCategoryId(categoryKeyword.getSubName());
				}
			}
		}
		return 100;
	}
}
